package com.cskaoyan.exception;

import com.cskaoyan.bean.common.BaseRespVo;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理
 * @author Fyy
 * @since 2022/12/30 11:16
 */

@RestControllerAdvice
public class ExceptionControllerAdvice {
    //处理参数校验失败抛出的异常
    @ExceptionHandler(ValidationException.class)
    public BaseRespVo invalidParameter (ValidationException exception){
        return BaseRespVo.invalidParameter(exception.getMessage());
    }

    //处理json字符串数据类型与接收类成员变量数据类型对应不上的异常
    @ExceptionHandler(HttpMessageNotReadableException.class)
    public BaseRespVo invalidParameter (HttpMessageNotReadableException exception){
        BaseRespVo<Object> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(402);
        baseRespVo.setErrmsg("参数值不对");
        return baseRespVo;
    }
}
